﻿using System.Collections.Generic;
using System.Linq;
using System.Data;

namespace StudentInfo.Areas.StudentArea.Services
{
    public class MarkService
    {
        public static Mark Get(int markId)
        {
            using (var context = new StudentInfoEntities())
            {
                return context.Marks.FirstOrDefault(s => s.Id == markId);
            }
        }

        public static List<Mark> GetAll()
        {
            using (var context = new StudentInfoEntities())
            {
                return context.Marks.ToList();
            }
        }

        public static void Save(Mark mark)
        {
            using (var context = new StudentInfoEntities())
            {
                context.Marks.Attach(mark);
                context.Entry(mark).State = EntityState.Modified;
                context.SaveChanges();
            }
        }

        public static void Create(Mark mark)
        {
            using (var context = new StudentInfoEntities())
            {
                context.Marks.Add(mark);
                context.SaveChanges();
            }
        }

        public static void Delete(Mark mark)
        {
            using (var context = new StudentInfoEntities())
            {
                context.Entry(mark).State = EntityState.Deleted;
                context.SaveChanges();
            }
        }
    }
}